//
//  TODComparisonValueTransformer.m
//  Click Link or Button in Current Webpage
//
//  Created by itod on 3/31/07.
//  Copyright 2007 Todd Ditchendorf. All rights reserved.
//

#import "TODComparisonValueTransformer.h"


@implementation TODComparisonValueTransformer

+ (Class)transformedValueClass
{
    return [NSNumber class];
}


+ (BOOL)allowsReverseTransformation
{
    return NO;   
}


#pragma mark -

- (id)initWithNumber:(int)i comparisonType:(TODComparisonType)type;
{
	self = [super init];
	if (self != nil) {
		number = i;
		comparisonType = type;
	}
	return self;
}


- (id)transformedValue:(id)value
{
	BOOL result = NO;
	int inVal = [value intValue];

	switch (comparisonType) {
		
		case TODComparisonTypeLessThanOrEqualTo:
			result = (inVal <= number);
			break;
			
		case TODComparisonTypeLessThan:
			result = (inVal < number);
			break;
			
		case TODComparisonTypeEqualTo:
			result = (inVal == number);
			break;
			
		case TODComparisonTypeGreaterThan:
			result = (inVal > number);
			break;
			
		case TODComparisonTypeGreaterThanOrEqualTo:
			result = (inVal >= number);
			break;
			
	}
	
	return [NSNumber numberWithBool:result];
}

@end
